/**
 * @author Mahesh
 */
window.onload = onloadFunction;
function onloadFunction()
{
	// Event handlers
	document.getElementById('skipBreakButton').onclick = skipBreak;	
	
	// Display the next break scheduled in the notification.
	// The main window calculates next break without considering the current break.
	// So we add the break duration to get the exact time when the next break begins. 
	var nextBreakTime = new Date(localStorage.getItem('nextBreakTime'));
	nextBreakTime = new Date(nextBreakTime.getTime() + localStorage.getItem('micro_break_duration_minutes')*60*1000);
	document.getElementById('nextBreakTime').value = nextBreakTime;
	
	remainingBreakCountDownTimer();
} 

function skipBreak()
{
	window.close();
	if(!window.opener.closed)
	{
		window.opener.restartTimer();
	}	
}

function remainingBreakCountDownTimer()
{
	document.getElementById('breakEndCountDownTimer').value = localStorage.getItem('micro_break_duration_minutes')*60;
	beginClockTick();
}

function beginClockTick()
{
	var secondsRemaining = document.getElementById('breakEndCountDownTimer').value;	
	if(secondsRemaining - 1 > 0)
	{
		document.getElementById('breakEndCountDownTimer').value -= 1;
	}
	
	var clockTickTimer = setTimeout("beginClockTick()", 1000);
}